package com.cookbook.service.impl;

import com.cookbook.database.data.ShareMapper;
import com.cookbook.database.model.Share;
import com.cookbook.database.model.User;
import com.cookbook.service.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 毛川
 */
@Service
public class ShareServiceImpl implements ShareService {

    @Autowired
    ShareMapper mapper;

    @Override
    public List<Share> select(Integer page, Integer limit) {
        int offset = page * limit;
        return mapper.selectWithOffset(offset, limit);
    }

    @Override
    public List<Share> selectMyShare(User user, Integer page, Integer limit) {
        int offset = page * limit;
        return mapper.selectMySharesWithOffset(user.getUserId(), offset, limit);
    }

    @Override
    public void insert(Share share) {
        mapper.insert(share);
    }

    @Override
    public Long deleteSelfByShareId(User user, Integer shareId) {
        return mapper.deleteWithShareIdAndUserId(shareId, user.getUserId());
    }

}
